package train.DAY618;


public class Test2 {
    public static void main(String[] args)  {
      int[] a={5,6,7,2,3,44};
        int[] sort = quickSort(a,0,a.length-1);
        for (int i = 0; i < sort.length; i++) {
            System.out.print(sort[i]+"\t");
        }

    }


    //选择排序
    public static int[] sort(int[] nums){
        int max=0,temp=0;
        for (int i = 0; i < nums.length-1; i++) {
            max=nums[i];
            for (int j = 1+i; j < nums.length ; j++) {
                if(max<nums[j]) {
                    temp=nums[j];
                    nums[j]=max;
                    max=temp;
                }
            }
            nums[i]=max;
        }
        return nums;
    }

   //冒泡排序

    public static int[] Choic(int[] nums){
        int temp=0;
        for (int i = 0; i< nums.length-1; i++) {

            for (int j = 0; j < nums.length-i-1 ; j++) {
           if(nums[j]>nums[j+1]) {
               temp = nums[j];
               nums[j] = nums[j + 1];
               nums[j + 1] = temp;
           }
            }
        }
        return nums;
    }

    //插入排序

    public static int[] Insert(int[] nums) {
        int temp=0;
        int j=0;
        boolean c=false;
        for (int i = 1; i < nums.length; i++) {
            temp=nums[i];
            for ( j = i-1; j>=0; j--) {
                if (nums[j] < temp)
                    nums[j + 1] = nums[j];
                else  break;
            }

            nums[j+1]=temp;

            }


        return nums;
    }


    //快排
    public static int[] quickSort(int[] nums,int low,int high){
        int l=low,h=high;
        int temp=0;
        int base=nums[low];
        while(l<h){

            while(l<h){
                if(nums[h]>base) break;
                h--;
            }
            if(l<h){
                temp=nums[h];
                nums[h]=nums[l];
                nums[l]=temp;
                l++;
            }

            while(l<h){
                if(nums[l]<base) break;
                l++;
            }
            if(l<h){
                temp=nums[h];
                nums[h]=nums[l];
                nums[l]=temp;
                h--;

            }

        }

        if(l>low) quickSort(nums,low,l-1);
        if(h<high) quickSort(nums,l+1,high);
        return nums;
    }
}
